{include file="layout/header" title="挂售记录" /}
	<div class="view-body">
    {include file="layout/menu" /}
		<div class="view-product">
			<div class="company_identify">
				<div class="manage-head">
					<h6 class="padding-left manage-head-con">挂售记录</h6>
				</div>

				<form class="layui-form" action="{:url('admin/user/sell')}" method="post" name="form">
					<div class="layui-form-item">
					    <label class="layui-form-label">用户名</label>
						<div class="layui-input-inline">
					      	<input type="text" name="username" class="layui-input">
					    </div>
						<div class="layui-input-inline">
					      	<button class="layui-btn layui-btn-primary">筛选</button>
					    </div>
					</div>
				</form>
				
				<div class="offcial-table tr-border table-margin clearfix">
					<div class="tr-th clearfix">
						<div class="th w5">ID</div>
						<div class="th w10">用户名</div>
						<div class="th w10">接单人</div>
						<div class="th w5">申请金额</div>
						<div class="th w5">手续费</div>
            			<div class="th w5">应付金额</div>
						<div class="th w10">挂售时间</div>
						<div class="th w10">超时时间</div>
						<div class="th w20">备注</div>
						<div class="th w10">状态</div>
						<div class="th w10">操作</div>
					</div>
						{volist name="list" id="v"}
						<div class="tr clearfix border-bottom-none">
							<div class="td w5">{$v.id}</div>
							<div class="td w10">{$v.username}</div>
							<div class="td w10">{:get_userinfo($v['agent_id'])}</div>
							<div class="td w5">{$v['money'] + $v['fee']}</div>
							<div class="td w5">{$v.fee}</div>
							<div class="td w5">{$v.money}</div>
							<div class="td w10">{:date('m-d H:i:s',$v['time'])}</div>
							<div class="td w10">{:date('m-d H:i:s',$v['timeout'])}</div>
							<div class="td w20">{$v.note}</div>
							<div class="td w10">
								{eq name="v.status" value="0"}挂售中{/eq}
				            	{eq name="v.status" value="1"}已接单{/eq}
				            	{eq name="v.status" value="2"}已支付{/eq}
				            	{eq name="v.status" value="3"}已完成{/eq}
							</div>
							<div class="td w10">
								{if $v['status'] eq 1 or $v['status'] eq 2}
									<button data-sell_id="{$v.id}" class="layui-btn layui-btn-mini layui-btn-normal delayed">延时</button>
								{/if}
								{if $v['status'] eq 2}
									<button data-sell_id="{$v.id}" class="layui-btn layui-btn-mini layui-btn-danger reset">重置</button>
								{/if}
							</div>
						</div>
						{/volist}
				</div>

				<div class="fl margin-top padding-big-left">
					
				</div>

				<div class="fr padding-big-right">
					<div class="page">
						{$list->render()}
					</div>
				</div>

			</div>
		</div>
	</div>
	<script type="text/javascript">
		new Form('form').init({$post});
	    layui.use(['form', 'layer'], function(){
			var $ = layui.jquery;
    		var layer = layui.layer;

    		$(".delayed").click(function() {
    			var sell_id = $(this).data('sell_id');
    			layer.prompt({
				  	title: '延长超时时间，单位：小时',
				}, function(hour, index, elem){
					if(!/^\+?[1-9][0-9]*$/.test(hour)){
						layer.msg('请输入一个整数');
						return;
					}
				  	$.post('{:url("admin/User/delayed")}', {id:sell_id,hour:hour}, function(res) {
		            	if(res.success == 1){
		            		layer.msg(res.msg, {
			                    time: 1000
			                }, function() {
			                    location.reload();
			                });
		            	}else{
		            		layer.msg(res.msg);
		            	}
		            },'json');
		            layer.close(index);
				});
		        return false;
		    });

		    $(".reset").click(function() {
    			var sell_id = $(this).data('sell_id');
    			layer.confirm('重置挂单为挂售中状态，扣除代理违约金，补偿挂单人', {
			            btn: ['确定', '取消'],
			            icon: 3
			        }, function(index) {
			            layer.close(index);
			            $.post('{:url("admin/user/reset")}', {id: sell_id}, function(res) {
			            	if(res.success == 1){
			            		layer.msg(res.msg, {
				                    time: 1000
				                }, function() {
				                	location.reload();
				                });
			            	}else{
			            		layer.msg(res.msg);
			            	}
			            });
			        });
		        return false;
		    });

		});
	</script>
{include file="layout/footer" /}
